; (function () {
  class Subscribe {
    constructor() {
      this.pool = [];
    }
    includes(fn) {
      return this.pool.includes(fn);
    }
    add(fn) {
      if (!this.includes(fn)) this.pool.push(fn);
      return this;
    }
    remove(fn) {
      /**
       *  let sub = new Subscribe();
      let fn1 = function () {
        console.log('fn1')
      }
      let fn2 = function () {
        console.log('fn2')
      }
      let fn3 = function () {
        console.log('fn3')
        sub.remove(fn1)
        sub.remove(fn2)

      }
      let fn4 = function () {
        console.log('fn4')
      }
      sub.add(fn1)
      sub.add(fn1)
      sub.add(fn2)
      sub.add(fn1)
      sub.add(fn3)
      sub.add(fn4)
      setInterval(() => {
        sub.fire();
      }, 1000);
       * 
       let pool = this.pool;
       for (let i = 0, len = pool.length; i < len; i++) {
         if (fn === pool[i]) {
           pool.splice(i, 1); 针对以上的情况，不可靠的，数组索引影响, 采用过滤删除已经存在的
           break;
          }
        }
      */

      // 取消订阅
      if (this.includes(fn)) {
        this.pool = this.pool.filter(f => f !== fn);
      }
      return this;
    }
    fire(...args) {
      let pool = this.pool;
      pool.forEach(f => f(...args));
    }
  }
  window.Subscribe = Subscribe;
})();